package org.file5.controller.rest;

import org.apache.log4j.Logger;
import org.file5.domain.Article;
import org.file5.service.ServiceFascade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class DataServiceController {

	private final Logger logger = Logger.getLogger(this.getClass());

	@Autowired
	private ServiceFascade sf;



	/**
	 * 
	 * @param requester the request site uid e.g. goodingsale.appspot.com
	 * @param code used to verify the requester 
	 * @return JSON 数据格式
	 */
	@RequestMapping(value = "/dataservice/article/{uid}", method = RequestMethod.GET)
	public ModelAndView getArticle(
			@PathVariable("uid") String uid,
			@RequestParam(value="requester",required=false) String requesterUid,
			@RequestParam(value="code",required=false) String code, Model model
			) {
		ModelAndView mav = new ModelAndView();
 
		// TODO: we should check manager
		// TODO: we should check quota
		 
		Article article = sf.getArticleService().find(uid, true);
 
		mav.addObject(article);

		return mav;
	}


}
